package com.heima.test17;

import java.util.concurrent.atomic.AtomicInteger;

class A implements Runnable {
    // int num = 0;
    AtomicInteger num = new AtomicInteger();

    @Override
    public void run() {
        for (int i = 0; i < 100000; i++) {
            // num.incrementAndGet();// ++num
            num.getAndIncrement();//num++  num+=5
        }
        System.out.println(num);
    }
}
//乐观锁   CAS
//synchronized 悲观锁

public class Demo01 {
    public static void main(String[] args) {
        A a = new A();
        new Thread(a).start();
        new Thread(a).start();
    }
}
